The HTTP service used for SEXPR based RPC calls currently serializes all
authorEwan Mellor <ewan@xensource.com>
Thu, 7 Dec 2006 12:07:53 +0000 (12:07 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 7 Dec 2006 12:07:53 +0000 (12:07 +0000)
incoming client requests. Since some requests can take non-trivial time
blocking out other clients in this way has bad consequences. The attached
patch makes XenD spawn a new thread to handle each incoming HTTP request.
This same approach is already taken in the XML-RPC service in XenD so I
don't anticipate any multi-thread issues (at least none which don't already
exist).

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/python/xen/web/httpserver.py

index bcf5dbd6b1aa7e10fc4889806b129acae8b49892..2326a2b875a8c2abb85cdc03d311a3abf2c20bb6 100644 (file)
@@ -264,7 +264,32 @@ class HttpServerRequest(http.HttpRequest):
             s += x + "/"
             self.write(' <a href="%s">%s</a>/' % (s, x))
         self.write("</h1>")
-        
+
+class HttpServerClient:
+
+    def __init__(self, server, sock, addr):
+        self.server = server
+        self.sock = sock
+        self.addr = addr
+
+    def process(self):
+        thread = threading.Thread(target=self.doProcess)
+        thread.setDaemon(True)
+        thread.start()
+
+    def doProcess(self):
+        try:
+            rp = RequestProcessor(self.server, self.sock, self.addr)
+            rp.process()
+        except SystemExit:
+            raise
+        except Exception, ex:
+            print 'HttpServer>processRequest> exception: ', ex
+            try:
+                self.sock.close()
+            except:
+                pass
+
 class HttpServer:
 
     backlog = 5
@@ -286,8 +311,8 @@ class HttpServer:
 
         while not self.closed:
             (sock, addr) = self.accept()
-            self.processRequest(sock, addr)
-
+            cl = HttpServerClient(self, sock, addr)
+            cl.process()
 
     def stop(self):
         self.close()
@@ -314,19 +339,6 @@ class HttpServer:
         except:
             pass
 
-    def processRequest(self, sock, addr):
-        try:
-            rp = RequestProcessor(self, sock, addr)
-            rp.process()
-        except SystemExit:
-            raise
-        except Exception, ex:
-            print 'HttpServer>processRequest> exception: ', ex
-            try:
-                sock.close()
-            except:
-                pass
-
     def getServerAddr(self):
         return (socket.gethostname(), self.port)